<%-- 
    Document   : filtrador
    Created on : 16-mar-2012, 11:49:08
    Author     : Maillo
--%>
<%@page import="net.sf.json.*"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.DriverManager"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%!
String formatear(String categoria){
    
    categoria = categoria.trim().toLowerCase();
    categoria = categoria.replace ('à','a');
    categoria = categoria.replace ('é','e');
    categoria = categoria.replace ('í','i');
    categoria = categoria.replace ('ó','o');
    categoria = categoria.replace ('ú','u'); 
    
    return categoria;
}
%>

<%


String $_categoria = formatear(request.getParameter("categoria"));

String adevolver = "";

//JSONArray arrayObj=new JSONArray();
//arrayObj.add($_categoria);

 //Conexion BBDD
    //*****************************************************************
    String driver = "org.apache.derby.jdbc.EmbeddedDriver";
    String connectionURL = "jdbc:derby://localhost:1527/ecommerce;create=true";
    String queryString = "select * from productos WHERE categoria='"+$_categoria+"'";
    adevolver += queryString;
    try {
        Class.forName(driver);
    } catch (java.lang.ClassNotFoundException e) {
        e.getMessage();
    }
    Connection conn;
  try {
                    conn = DriverManager.getConnection(connectionURL);
                    Statement stmt2 = conn.createStatement();
                    ResultSet rs = stmt2.executeQuery(queryString);
                    adevolver += ("<table border=1>");
                    adevolver +=("<th>Nombre</th>");
                    adevolver+=("<th>Imagen</th>");
                    adevolver+=("<th>Precio</th>");
                    adevolver+=("<th>Categoria</th>");
                    while (rs.next()) {
                        adevolver+=("<tr><td>" + rs.getString(1) + "</td>");
                        adevolver+=("<td>" + rs.getString(4) + "</td>");
                        adevolver+=("<td>" + rs.getString(3) + "</td>");
                        adevolver+=("<td>" + rs.getString(2) + "</td></tr>");
                    }
                    adevolver+=("</table>");

                    rs.close(); 
                } catch (Exception e) {
                    e.getMessage();
                }
    //*****************************************************************
out.print(adevolver);
//Creando la tabla filtrada.
%>



